﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace giaipt
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            throw new NotImplementedException();
        }

        private void mnTinh_Click(object sender, RoutedEventArgs e)
        {
            double a = Convert.ToDouble(tb_a.Text);
            double b = Convert.ToDouble(tb_b.Text);
            double c = Convert.ToDouble(tb_c.Text);
            double x1, x2, x;
            double delta = (b * b) - (4 * a * c);
            if (a == 0)
            {
                if (b == 0 && c != 0)
                    tb_kq.Text = Convert.ToString("phuong trinh vo nghiem");
                else
                {
                    x = -c / b;
                    tb_kq.Text = Convert.ToString("phuong trinh co nghiem " + x);

                }
            }
            else
            {
                if (delta < 0)
                    tb_kq.Text = Convert.ToString("phuong trinh vo nghiem");

                else if (delta == 0)
                {

                    x = -b / 2 * a;
                    tb_kq.Text = Convert.ToString("phuong trinh co nghiem" + x);
                }
                else
                {
                    x1 = (-b - (float)Math.Sqrt(delta)) / 2 * a;
                    x2 = (-b + (float)Math.Sqrt(delta)) / 2 * a;
                    Console.WriteLine("phuong trinh co nghiem " + x1.ToString());
                    Console.WriteLine("phuong trinh co nghiem " + x2.ToString());
                    tb_kq.Text = Convert.ToString("phuong trinh co nghiem  \n " + x1 + "và" + x2);
                }


            }
        }





        private void mnXoa_Click(object sender, RoutedEventArgs e)
        {
            tb_a.Text = null;
            tb_b.Text = null;
            tb_c.Text = null;
            tb_kq.Text = null;

        }

        private void mnThoat_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Bạn có muốn thoát hay không", "Tâm Gà thông báo", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Yes)
            {
                this.Close();
            }
        }
    }
}
